<template>
  <div>
    <el-form ref="formData" :model="formData" label-width="80px" :rules="formRules">
      <el-form-item label="字典名称" prop="name">
        <el-input v-model="formData.name" />
      </el-form-item>
      <el-form-item label="描述" prop="remarks">
        <el-input v-model="formData.remarks" />
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  props: {
    formId: {
      type: Number,
      default: null
    }
  },
  data() {
    return {
      dialogLoading: false,
      formData: {
        id: '',
        name: '',
        remarks: ''
      },
      formRules: {
        name: [
          { required: true, message: '请输入字典名称' }
        ]
      }
    }
  },
  mounted() {
    this.getFormData()
  },
  methods: {
    getFormData() {
      if (this.formId) {
        this.$api.dict.find(this.formId).then(res => {
          this.formData = res.data
        })
      }
    },
    submitForm() {
      this.$refs.formData.validate(valid => {
        if (valid) {
          if (!this.formData.id) {
            this.$api.dict.save(this.formData).then(res => {
              this.$emit('submitSuccess')
            })
          } else {
            this.$api.dict.update(this.formData).then(res => {
              this.$emit('submitSuccess')
            })
          }
        }
      })
    }
  }
}

</script>
<style scoped>
</style>
